package com.qfedu.controller;

import com.qfedu.entity.ResponseData;
import com.qfedu.entity.Skill;
import com.qfedu.entity.User;
import com.qfedu.service.SkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
public class SkillController {
    @Autowired
    private SkillService skillService;

    //查询所有技术
    @RequestMapping("/findAllSkill")
    public ResponseData findAllSkill(int page, int limit) {
        return skillService.findAllSkill(page, limit);
    }

    //增加技术
    @RequestMapping("/addSkill")
    public ResponseData addSkill(Skill skill, HttpServletRequest request) {
        ResponseData responseData = new ResponseData();
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("loginUser");
        skill.setCreateTime(new Date(System.currentTimeMillis()));
        skill.setuNo(user.getNo());
        boolean result = skillService.addSkill(skill);
        if (result) {
            responseData.setCode(ResponseData.SUCCESS_CODE);// 成功
            responseData.setMsg(ResponseData.SUCCESS_MSG);
        } else {
            responseData.setCode(ResponseData.FAIL_CODE);// 成功
            responseData.setMsg(ResponseData.FAIL_MSG);
        }
        return responseData;
    }


}
